///医院列表

var app = getApp()
//常量数据配置
var ConstantData = require('../../../../common/constant_data.js')
//获取应用实例  
Page({
  
  data: {
    hospitalList:[],
    rental_role:1,    ///是否能查租金
    searchInputStat:false
  },


  onLoad: function () {
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    app.executeRequest(function(header){
      wx.request({
        url: ConstantData.CONSTATNT_DATA.BASE_URL + '/lease_statistic/hospital/list',
        header:header,        
        success: function (res) {          
          console.log("hostipal---->", res);
          var list = Array();
          for(var i=0;i<res.data.length;i++) {
            var hosipitalId = res.data[i].lbm_id;
            var buttons = res.data[i].buttons;
            if(!buttons){
              continue;
            }
            var index = buttons.indexOf(";"+hosipitalId+":1;");
            if (index != -1 || buttons == 'all') {
              res.data[i].isvistrent = 1;
            }
            var noback_index = buttons.indexOf(";" + hosipitalId.split('-')[0]+'-chair' + ":2;");
            if (noback_index != -1 ) {
              res.data[i].isvistnoback = 1;
            }

            var leaseIsViewIndex = buttons.indexOf(";" + hosipitalId + ":3;");
            if(leaseIsViewIndex == -1) {
              res.data[i].isLeaseView = 1;
            }else {
              res.data[i].isLeaseView = 0;
            }

            list.push(res.data[i]);
          }
          that.setData({
            hospitalList:list,
            originHospitalList:list,
            searchInputStat:list.length > 10,
          })
          wx.hideLoading()
        }
      })
    });  

  },

  onShow:function(){

  },
 
  /** 
   * 点击 ,进入租赁信息
   */
  toLeaseList: function (e) {
    console.log(e);
    var mecId = e.currentTarget.dataset.hospitalid;
    var hospitalName = e.currentTarget.dataset.hospitalname;
    var isReal = e.currentTarget.dataset.real;
    wx.navigateTo({
      url: '../leaselist/leaselist?mecId=' + mecId + "&hospitalName=" + hospitalName +"&isReal=" + isReal,
    });
  },
  /**
   * 点击 ,进入租金收入
   */
  toRentalList:function(e)
  {
    var mecId = e.currentTarget.dataset.hospitalid;
    var hospitalName = e.currentTarget.dataset.hospitalname;
    wx.navigateTo({
      url: '../rentallist/rentallist?mecId=' + mecId + "&hospitalName=" + hospitalName+"&isNoReal=0",
    });
  },
  toNoRealRentalList:function(e) {
    var mecId = e.currentTarget.dataset.hospitalid;
    var hospitalName = e.currentTarget.dataset.hospitalname;
    wx.navigateTo({
      url: '../rentallist/rentallist?mecId=' + mecId + "&hospitalName=" + hospitalName+"&isNoReal=1",
    });
  },
  /**
   * 点击 ,进入未归还设备列表
   */
  toNoBackEquList: function (e) {
    var mecId = e.currentTarget.dataset.hospitalid;
    var hospitalName = e.currentTarget.dataset.hospitalname;
    wx.navigateTo({
      url: '../nobacklist/nobacklist?mecId=' + mecId + "&hospitalName=" + hospitalName,
    });
  },
  /**
  * 页面上拉触底事件的处理函数
  */
  onReachBottom: function () {
    // wx.showLoading({
    //   title: 'loading',
    // });
    // setTimeout(function(){
    // getApp().hideLoading();
    // },3000);
    // var that = this;
    // if (that.data.loading && !that.data.loadingComplete) {
    //   that.setData({
    //     pageNum: that.data.pageNum + 1,  //每次触发上拉事件，把searchPageNum+1  
    //   });
    //   that.getApageLeaseRecord();
    // }
  },

  inputHospital:function(e) {
    this.setData({
      inputHospital: e.detail.value
    });

    var hospitals = new Array();
    var originHospitalList = this.data.originHospitalList;
    for (var i = 0; i < originHospitalList.length; i++) {
      if (originHospitalList[i].lbm_name.indexOf(this.data.inputHospital) != -1) {
        hospitals.push(originHospitalList[i]);
      }
    }
    if (this.data.inputHospital == '') {
      hospitals = this.data.originHospitalList;
    } else if (hospitals.length == 0) {
      this.setData({
        noneDataStat: true
      });
    } else {
      this.setData({
        noneDataStat: false
      });
    }
    this.setData({
      hospitalList: hospitals
    })

  }
})  

function test() {

var date=new Date();
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var day = date.getDate()  ;

  
  console.log("year="+year);
  console.log("month=" + month);
  console.log("day=" + day);
}